/**
 * 
 */
package com.net.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.net.dao.AttendanceDao;
import com.net.domain.Student;
import com.net.domain.StudentAttendanceDetail;
import com.net.web.form.AttendanceSearchForm;

/**
 * @author Dinesh
 *
 */
public class AttendanceServiceImpl implements AttendanceService {
	
	private AttendanceDao attendanceDao;
	
	private StudentService studentService;
	
	/* (non-Javadoc)
	 * @see com.net.service.AttendanceService#getAllEligibleStudents(java.util.HashMap)
	 */
	@Override
	public List<StudentAttendanceDetail> getAllEligibleStudents(
			AttendanceSearchForm searchQuery) {
		//TODO: check input arguments
		
		List<StudentAttendanceDetail> studentList = 
				attendanceDao.getAllEligibleStudents(searchQuery);
		
		// Convert student id to Student object
		for(StudentAttendanceDetail studentAttendance : studentList) {
			Student student = studentService.getStudent(studentAttendance.getStudentId());
			
			studentAttendance.setStudent(student);
		}
		return studentList;
	}
	
	@Override
	public void insertAttendanceDetails(List<StudentAttendanceDetail> attendanceList) {
		// Write the attendanceList through DAO
		
		attendanceDao.insertAttendanceDetails(attendanceList);
		
	}

	public AttendanceDao getAttendanceDao() {
		return attendanceDao;
	}

	@Autowired
	public void setAttendanceDao(AttendanceDao attendanceDao) {
		this.attendanceDao = attendanceDao;
	}

	public StudentService getStudentService() {
		return studentService;
	}

	@Autowired
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}


	@Override
	public List<StudentAttendanceDetail> getAttendanceStatus(Student student,
			Date startDate, Date endDate) {
		// TODO Auto-generated method stub
		List<StudentAttendanceDetail> studentList = 
				attendanceDao.getAttendanceStatus(student,startDate,endDate);
		
		for(StudentAttendanceDetail studentAttendance : studentList) {			
			
			// Set other data if required
			
			studentAttendance.setStudent(student);
		}
		       return studentList;
	}
}
